/*
 * @Description: 转发
 */
// 引入基础数据
import { useBaseInfoWithOut } from '@/store/modules/base-info';
import { useSummaryCommentWithOut } from '@/store/modules/summary/comment';
import globalData from '@/plugins/data';
import globalMethods from '@/plugins/methods';

const useSummaryComment = useSummaryCommentWithOut();
// import SummaryForward from './index.vue';
// function forward() {
//     const useBaseInfo = useBaseInfoWithOut();
//     let ctx = null;
//     this.$confirm({
//         title: this.$i18n('govdoc.collaboration.forwarding'),
//         content: (h) => (
//             <SummaryForward
//                 isSetSecretLevel={!useBaseInfo.baseInfo.secretLevel.hidden}
//                 secretLevel={useBaseInfo.baseInfo.secretLevel.value}
//                 onGetContext={(v) => (ctx = v)}
//             />
//         ),
//         class: 'summary-forward',
//         closable: true,
//         width: 570,
//         onOk: () =>
//             new Promise((resolve, reject) => {
//                 const data = ctx.getData();
//                 //没选人，不能关闭
//                 if (!data.selected.value) {
//                     this.$message.error('流程不能为空！');
//                     return reject();
//                 }
//                 console.log(ctx.getData());
//                 //调接口
//             }),
//     });
// }



//老的转发适配
function forward() {
    new Promise(resolve => {
        if (globalData.isCap4){
            const formsonsFilterDataFn = window._getZWIframe()?.csdk?.core?.getFormsonsFilterData;
            if (formsonsFilterDataFn){
                formsonsFilterDataFn((res)=>{
                    let conditionId = res?.cId||'';
                    resolve(conditionId);
                })
                return;
            }
        }
        resolve();
    }).then((conditionId='')=>{
        const url = `${globalData.ctxPath}/collaboration/collaboration.do?method=showForward&data=${globalData.summaryId}_${globalData.affairId},`;
        const toCollWin = window.toCollWin;
        const dialog = globalMethods.dialog({
            id: 'showForwardDialog',
            url,
            width: 530,
            height: 416,
            bodyStyle:'padding:0',
            title: this.$i18n('common.toolbar.transmit.col.label'),
            checkMax: true,
            transParams: {
                commentContent: useSummaryComment.textContent,
                commentAttFiles: JSON.stringify(useSummaryComment.attachments),
                commentAttDocs: JSON.stringify(useSummaryComment.relationDoc),
                conditionId,
                collaborationForward: () => {
                    dialog.close();
                }
            },
            afterClose() {
                //关闭之后再放回去
                window.toCollWin = toCollWin;
            },
            onCancel() {
                dialog.close();
            },
            onConfirm: () => {
                console.log(dialog.getValue());
            },
        });
        //适配他关闭。老协同转发成功，弹出提示。点击确定会调这个关闭
        window.toCollWin = dialog;  
    })
}

export default function () {
    return new Promise((resolve) => {
        forward.call(this);
        resolve();
    });
}
